package cn.qayy.service.impl;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import cn.qayy.dao.UserMapper;
import cn.qayy.pojo.User;
import cn.qayy.service.IUserService;

@Service("userService")
public class UserServiceImpl  implements IUserService{
	/*** 注入userMapper接口 **/
	@Resource
	private UserMapper userMapper;
	
	public User getUserById(int userId) {
		return this.userMapper.selectByPrimaryKey(userId);
	}
   
	@Override
	public int saveUser(User user) {
		return userMapper.insert(user);  
	}

	@Override
	public User loginUser(String username, String password) {
		User user = null;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("username", username);
		params.put("password", password);
		try {
			/**
			 * ibaties的xml配置文件<sqlMap namespace="system">，
			 * commonBatiesBaseDao底层操作数据的增删改查是通过sqlMapClient对象完成的，sqlMap用id为key,
			 * select为value，形成key-value键值对的sqlMap。
			 */
			user = (User) userMapper.loginUser(params);
			System.out.println("user="+user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;
	}

}
